document.write('<script type="text/javascript" src="' + basePath + 'js/kindeditor.js"></script>');
document.write('<script type="text/javascript" src="' + basePath + 'js/lang/zh_CN.js"></script>');

var editorHtml = "";
var _htmlUploadUrl="all";
var _indexUrl="indexUrl";
var _htmlTitle='title';
$(function(){
	
	var htm="<div id=\"editIndex_yinying\" class='yinying' style='z-index:300'></div><div id=\"window_editor\" class=\"hideDiv setHTML\"><div><span>页面名称:</span><input type='text' id='htmlName_edit' /> </div>  <textarea id=\"editIndex\" name=\"editIndex\"></textarea><div class=\"BottomBtn\"><input type=\"button\" value=\"确定\" class=\"common_btn\" onclick=\"saveHtml()\" ><input type=\"button\" value=\"取消\" style=\"background-color: red;\" class=\"common_btn\" onclick=\"cancelHtml()\" ></div></div>"
	$("body").prepend(htm);
	
	_loadHtmlUploadParam();
	$("#editIndex_btn").click( function(){
		$("#window_editor,#editIndex_yinying").show();
		editor= KindEditor.create('#editIndex', {
			pasteType : 2,
			height : 400,
			width:670
		});
		if(IsNotEmpty($("#"+_indexUrl).val())){
			getHtmlByUrl($("#"+_indexUrl).val());
		}else{
			editorHtml="";
		}
		editor.html(editorHtml);
		addMargin($("#window_editor"));		
	});
});

function saveHtml(){
	if(IsEmpty(editor)&&IsEmpty($("#"+_indexUrl).val())){
		editorHtml="";
	}else{	
		editorHtml=editor.html();
		var htmlName_edit = $("#htmlName_edit").val()
		var dt= _insertInfoNoSucceedMessage('../htmlUtils/upload/sys/'+_htmlUploadUrl, {'htmlStr':editorHtml,'title':htmlName_edit});
		if(dt.state==0){
			
			$("#"+_indexUrl).val(_getStringOfJson(0, dt, "indexUrl"));
		}
	}
	
	editor.remove("#editIndex");
	$("#window_editor,#editIndex_yinying").hide();
	}

function cancelHtml(){
	
	editor.remove("#editIndex");
	$("#window_editor,#editIndex_yinying").hide();
	}
function _loadHtmlUploadParam(){
	
}
function getHtmlByUrl(url){
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../htmlUtils/find/loadHtml",
		data:{'htmlUrl':url},
		success : function(data) {
			var rst = JSON.parse(data);
					if(rst.state==0){
						editorHtml=getHeadIndexValue(0, rst, "htmlStr");	
					}
		}	
	});
}